# ommbot/aliases.py
#
#

""" command aliases """

__copyright__ = 'this file is in the public domain'

import ommbot.persist
import os

class Aliases(ommbot.persist.Persist):

    def __init__(self, path):
        super(Aliases, self).__init__(path + os.sep + 'aliases')
        if not self.data:
            self.data = {}

    def reverse(self, what):
        """ get the reverse of an alias """
        for i, j in self.data.iteritems():
            if j == what:
                return i

    def check(self, ievent):
        """ check if alias is available """
        try:
            cmnd = ievent.txt.split()[0]
            alias = self.data[cmnd]
            ievent.txt = ievent.txt.replace(cmnd, alias, 1)
        except:
            pass
